<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
        .level2{
            overflow: hidden;
            width: 300px;
            height: 300px;
            margin: 100px auto;
            background-color: blueviolet;
            text-align: center;
        }
        .level3{
            width: 150px;
            height: 150px;
            margin: 50px auto;
            background-color: pink;
            text-align: center;
        }
    </style>
    <script>
        window.onload = function(){
            const level3Obj = document.querySelector(".level3")
            const level2Obj = document.querySelector(".level2")


            /* 
                冒泡：当元素嵌套绑定事件的时候，会产生冒泡
             */

            // level3Obj.addEventListener("click",function(){
            //     alert("level3")
            // },false)

            // level2Obj.addEventListener("click",function(){
            //     alert("level2")
            // },false)

            // document.addEventListener("click",function(){
            //     alert("document")
            // },false)        //默认就是false，默认冒泡




            /* 
                捕获：会从事件的最顶层开始执行
             */
        

              level3Obj.addEventListener("click",function(){
                alert("level3")
            },true)

            level2Obj.addEventListener("click",function(){
                alert("level2")
            },false)    //先执行捕获的，在执行冒泡的

            document.addEventListener("click",function(){
                alert("document")
            },true)
            
        }
    </script>
</head>
<body>
    <div class="level2">
        <div class="level3">事件的冒泡</div>
    </div>
</body>
</html>